package com.jian.dao.impl;

import com.jian.dao.BaseBDao;
import com.jian.dao.TeacherDAO;

import java.sql.SQLException;

/**
 * @author Jiange
 * @create 2021-04-13-13:47
 */
public class Teacher extends BaseBDao implements TeacherDAO {
    @Override
    public int queryLogin(com.jian.pojo.Teacher teacher) {
        com.jian.pojo.Teacher one = null;
        String sql = "select * from teacher where username = ? and password = ? and account = ?";
        try {
            one = queryForOne(com.jian.pojo.Teacher.class,"select * from teacher where username = ?",teacher.getUsername());
            if(one == null){
                return -1;//用户名不存在
            }else{
                one = queryForOne(com.jian.pojo.Teacher.class,"select * from teacher where username = ? and password = ?",teacher.getUsername(),teacher.getPassword());
                if(one == null){
                    return -2;//密码错误
                }else{
                    one = queryForOne(com.jian.pojo.Teacher.class, sql, teacher.getUsername(), teacher.getPassword(), teacher.getAccount());
                    if (one == null){
                        return -3;//账号错误
                    }else return 1;//成功
                }
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            throw new RuntimeException();
        }
    }
}
